import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.time.LocalDate;

/**
 * @author: xinmi
 * @date: 2020/11/10
 * @description:
 */
public class FileWrite {

    public static void main(String[] args) {

        System.out.println("user_dir:" + System.getProperty("user.dir"));

        LocalDate localDate = LocalDate.now();
        String fileName = System.getProperty("user.dir") + "\\data\\GPS"+localDate.toString().replace("-","_")+".txt";
        System.out.println(fileName);

        File file = new File(fileName);
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream(file,true);
            String words = "2019年1月18日新追加内容!";
            byte[] bytes = words.getBytes();
            for(int i =0; i<bytes.length; i++){
                fos.write(bytes[i]);
            }
            System.out.println("追加内容成功");
        }catch (Exception e) {
            e.printStackTrace();
        }finally{
            try {
                fos.flush(); //强制刷新输出流
                fos.close(); //强制关闭输出流
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
